package com.lagou;

import com.lagou.bean.ComsumerComponet;
import com.lagou.filter.TPMonitorFilter;
import com.lagou.utils.Statistics;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class AnnotationConsumerMain  {
    public static void main(String[] args) throws  Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ComsumerComponet service = context.getBean(ComsumerComponet.class);

        ExecutorService executorService = Executors.newFixedThreadPool(2);
        //调用接口一
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                while (true){
                    String s = service.sayHelloOne("hello1",0);
                }
            }
        });

        //调用接口二
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                while (true){
                    String s = service.sayHelloTwo("hello2",0);
                }
            }
        });

        ScheduledExecutorService scht = Executors.newScheduledThreadPool(2);
        //开始任务调度
        scht.scheduleWithFixedDelay(new Statistics(TPMonitorFilter.queue1,"sayHelloOne"), 5000L, 5000L, TimeUnit.MILLISECONDS);
        scht.scheduleWithFixedDelay(new Statistics(TPMonitorFilter.queue2,"sayHelloTwo"), 5000L, 5000L, TimeUnit.MILLISECONDS);
       Thread.sleep(Long.MAX_VALUE);
    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static  class  ConsumerConfiguration{

    }
}
